'use strict'

const crypto = require('crypto')
const moment = require('moment')

module.exports = ({ ctx }) => ({
    // 加密
    handleEnCrypt(data, salt, type = 'md5') {
        return crypto.createHash(type).update(data + salt).digest('hex')
    },

    dateFormat(date, type = 'yyyy-MM-DD') {
        return moment(date).format(type)
    },

    //  成功统一响应
    success(res = {}) {
        ctx.body = {
            code: res.code || 200,
            data: res.data || null,
            msg: res.msg || '请求成功'
        }
        ctx.status = 200
    }
})